package org.groupg.demo.sshd;

import org.apache.sshd.common.config.keys.loader.pem.PEMResourceParserUtils;
import org.apache.sshd.common.config.keys.loader.KeyPairResourceLoader;
import org.apache.sshd.common.keyprovider.FileKeyPairProvider;
import org.apache.sshd.server.SshServer;

import java.nio.file.Paths;
import java.security.KeyPair;
import java.util.Collection;

public class SshServerWithPuttyKey {
    public static void main(String[] args) throws Exception {
        SshServer sshd = SshServer.setUpDefaultServer();
        sshd.setPort(2222);

        // 加载PuTTY格式的私钥
        KeyPairResourceLoader loader = KeyPairResourceLoader.EMPTY;
        Collection<KeyPair> keys = loader.loadKeyPairs(null,
            Paths.get("path/to/putty-private-key.ppk"), null);

        // 设置密钥提供者
        sshd.setKeyPairProvider((e) -> keys.iterator());

        // 其他配置...
        sshd.start();
        System.out.println("SSH server with PuTTY key started");

        Thread.sleep(Long.MAX_VALUE);
    }
}